package com.bw.zg3_day03lx

import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.bw.base.entity.NoticeBeanItem
import com.bw.base.mvvm.BaseViewModel
import com.bw.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
@HiltViewModel
class MainViewModel @Inject constructor(val apiService: ApiService): BaseViewModel() {

    fun getNotice():Flow<PagingData<NoticeBeanItem>>{
        return Pager(config = PagingConfig(pageSize = 10), pagingSourceFactory = {
            NoticeDataSource(apiService)
        }).flow.cachedIn(viewModelScope)
    }

}